package interceptor01.demo.exception;

import interceptor01.demo.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 报错异常
 *
 * @author summerkxy
 * */

@Slf4j
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(Exception.class)
    public ApiResponse<Void> exception(Exception e) {
        log.error("全局异常信息 ex={}", e.getMessage(), e);
        return ApiResponse.error();
    }

    @ExceptionHandler(value = CustomerException.class)
    public ApiResponse<Void> customExceptionHandler(CustomerException e) {
        return ApiResponse.fail(e.getCode(),e.getMessage());
    }
}
